#!/bin/bash
# -*- encoding: utf-8 -*-
#Modify Time :20/12/17 17:31
#Author:ttcandy
#nginx service manage script

#variables
nginx_install_doc="/usr/sbin/nginx"
nginxd="$nginx_install_doc/sbin/nginx"
pid_file='/run/nginx.pid'

# Source function library.
if [ -f /etc/init.d/functions ];then
    . /etc/init.d/functions
else
    echo "not found file /etc/init.d/functions"
    exit
fi

#function
start () {
#如果nginx 没有启动直接启动，否则报错 已启动
if [ -f $pid_file ];then
    nginx_process_id=`cat $pid_file`
    nginx_process_num=`ps aux | grep $nginx_process_id | grep -v "grep" |wc -l`

fi

if [ -f $pid_file ]&&[ $nginx_process_num -ge 1 ];then
    echo "nginx running..."
else
    if [ -f $pid_file ]&&[ $nginx_process_num -lt 1 ];then
        rm -f $pid_file
        daemon $nginx
    fi
daemon $nginx
fi
}

stop () {
    echo a
}

restart () {
    echo a
}

reload () {
    echo a
}

status () {
    echo a
}

#callable
case $1 in
start) start;;
stop) stop;;
restart) restart;;
reload) reload;;
status) status;;
*) echo "USAGE: $0 start|stop|restart|reload|status";;
esac